﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Shared/MasterPage.master" %>
<%@ Import Namespace="Typps" %>
<%@ Register Assembly="Typps" Namespace="Typps" TagPrefix="cc1" %>
<script runat="server">
    string tabspace = "   ";
    protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        TextBox1.Text = string.Empty;
    }
    void SetOptions()
    {
        if (TextBox1.Text == string.Empty)
        {
            if (RadioButtonList1.SelectedIndex == 0)
                tabspace = "\t";
            else
                tabspace = "   ";
        }
        bool removeAllFormatting = true;
        bool concatScriptBlocks = true;
        if (RadioButtonList2.SelectedIndex > 0)
        {
            removeAllFormatting = false;
            if (RadioButtonList2.SelectedIndex == 2)
                concatScriptBlocks = false;
        }
        HttpFormatFilter hff = new HttpFormatFilter(Response.Filter, tabspace, concatScriptBlocks, removeAllFormatting);
        Response.Filter = hff;
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        SetOptions();
    }

    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
        if (TextBox1.Text != string.Empty)
            tabspace = TextBox1.Text;
    }

    protected void Page_PreRender(object sender, EventArgs e)
    {
        if(!IsPostBack)
            SetOptions();
    }
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <div>
        <fieldset>
            <legend>White space</legend>
            <asp:RadioButtonList ID="RadioButtonList1" runat="server" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
                <asp:ListItem Text="Use a tab for indentation" Selected="True" Value="a"></asp:ListItem>
                <asp:ListItem Text="Use 3 spaces" Value="b"></asp:ListItem>
            </asp:RadioButtonList>
            <div>
                Or simply add in the textbox how much space you want when the html is getting formatted</div>
            <asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
        </fieldset>
        <br />
        <fieldset>
            <legend>Other options</legend>
            <asp:RadioButtonList ID="RadioButtonList2" runat="server">
                <asp:ListItem Text="Remove whitespace contained in the html" Value="a"></asp:ListItem>
                <asp:ListItem Text="Format the HTML and concat script blocks" Selected="True" Value="b"></asp:ListItem>
                <asp:ListItem Text="Format but do not concat script blocks" Value="c"></asp:ListItem>
            </asp:RadioButtonList>
        </fieldset>
        <p style="text-align: center">
            <asp:Button ID="Button2" runat="server" Text="Apply the new format" OnClick="Button2_Click" />
        </p>
        <h1>Typps Html Format filter</h1>
         <p>NOTE: <b>To see the transformation, you have to viewsource the page and look at the rendered html output. Infact a default filter has already been applied and you can already
        viewsource to notice how the html of this page is will formatted and how all scripts have been moved to the end of the file. Use the commands above to change the default
        selections and apply a new filter.</b></p>
        <p>This Html format filter is an extention of the built in html code parser that allows exclusion of html elements based on a black list created by the developer, a
        new feature in the HTML editor and it is triggered when the ElementsAllowed collection is filled with elements that the developer decides as valid markup, while everything
        else gets stripped off.</p>
        <p>The same Html code parser can be used as an Html Format filter as seen here in this demo.</p>
        <p>In fact the setup is quite simple. What follows is all the code you need to write to enable this fast, forward only, http filter :</p>
        <div>
            <pre>
                HttpFormatFilter hff = new HttpFormatFilter(Response.Filter, tabspace, concatScriptBlocks, removeAllFormatting);
                Response.Filter = hff;
            </pre>
        </div>
        <p>You end up with properly formatted html if you like your viewsource to be properly formatted otherwise, you can strip out whitespace, or even move
        all your script tags to the bottom of the page, in this way you enable a faster loading page to your users since the html loads first, then the script files will
        follow. Properly formatting eliminates excessive whitespaces in the markup, while making the viewsource of your pages readable.</p>
        <p>Make sure you test well if this filter works well on your pages as html unlike xml is unpredictable. So what ever floats our boat doesn't necessarily mean
        it won't tip over someone elses. In case you find a bug, report it.</p>
        <p>This filter is particularly useful if you have a cms that outputs a lot of dynamic content and thus having plenty of blank space in between tags within the markup. Or
        perhaps you just want to showoff a nicely formatted output? Why not, this is a simple setting you can make use of from within your global.asax handler for all your pages. 
        Completely eliminating white space is also a good saving on heavily trafficked websites. Google does this and so does msn portal, yahoo etc.</p>
    </div>
</asp:Content>
